package com.day1011;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class MyPanel extends JPanel {
    MapReader mapReader = new MapReader();
    BufferedImage[][] images = new BufferedImage[11][11];
    String[][] numArray = mapReader.readMAP();
    public MyPanel() throws Exception {
        for (int index = 0; index < numArray.length; index++) {
            for (int i = 0; i < numArray[index].length; i++) {
                File fileImage = new File("F:\\task\\map0\\" + Integer.parseInt(numArray[index][i]) + ".png");
                BufferedImage image = null;
                try {
                    image = ImageIO.read(fileImage);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                images[index][i] = image;
            }
        }
    }


    public void paint(Graphics g){
       // g.drawString("我是中国人",100,100);
        for (int i = 0; i < numArray.length; i++) {
            for (int j = 0; j < numArray[i].length; j++) {
                g.drawImage(images[i][j],72 * j,72 * i,images[i][j].getWidth(),images[i][j].getHeight(),
                        null);
            }

        }
    }
}
